﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="QuotationGenerator.aspx.cs" Inherits="TireService.Web.View.SalesView.QuotationGenerator" %>

<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxRoundPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1.Export, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxLoadingPanel" TagPrefix="dx" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="img1" alt="" src="~/Images/Medium/money.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h3><asp:Label ID="lblQuotationGenerator" runat="server" Text="Tilbuds generator"></asp:Label></h3>
            </td>
        </tr>
    </table>
    <hr />

    <!-- Javascript of action dropdown list -->
    <script language="javascript" type="text/javascript">

        // Function that handles when customer filter is selected
        function CustomerFilterSelected() {
            if (rblCustomerFilter.GetValue() == "0") {
                ddlBusinessCustomer.SetEnabled(false);
            }
            if (rblCustomerFilter.GetValue() == "1") {
                ddlBusinessCustomer.SetEnabled(true);
            }
        }

        function UpdateTireSetTargetGroup() {

            LoadingPanel.Show();
            
            // Prepare input
            var input = ddlTireType.GetValue() + '|';
            input += txtVF.GetText() + '|';
            input += txtHF.GetText() + '|';
            input += txtVB.GetText() + '|';
            input += txtHB.GetText() + '|';
            input += rblCustomerFilter.GetValue() + '|';
            input += ddlBusinessCustomer.GetValue();

            gvTireSetTargetGroup.PerformCallback(input);
        }

        function CreateSingleQuotation(tiresetid) {
            window.open('QuotationCalculator.aspx?TireSetId=' + tiresetid + "&VF=" + txtVF.GetText() + "&HF=" + txtHF.GetText() + "&VB=" + txtVB.GetText() + "&HB=" + txtHB.GetText() + "&TireType=" + ddlTireType.GetValue() + "&TargetGroupType=0&Business=" + rblCustomerFilter.GetValue() + "&CustomerId=" + ddlBusinessCustomer.GetValue(), '_self', 'Tilbudsberegner');
        }

        function CreateGroupQuotation(tiresetid) {
            window.open('QuotationCalculator.aspx?TireSetId=' + tiresetid + "&VF=" + txtVF.GetText() + "&HF=" + txtHF.GetText() + "&VB=" + txtVB.GetText() + "&HB=" + txtHB.GetText() + "&TireType=" + ddlTireType.GetValue() + "&TargetGroupType=1&Business=" + rblCustomerFilter.GetValue() + "&CustomerId=" + ddlBusinessCustomer.GetValue(), '_self', 'Tilbudsberegner');
        }

        function OnCallbackUpdateTireSetTargetGroupComplete(s, e) {

            LoadingPanel.Hide();
        }

        function CallbackError() {
            alert('Fejl opstod - prøv venligst igen');
        }

    </script>

    <dx:ASPxLoadingPanel ID="LoadingPanel" Text="Vent venligst..." ClientInstanceName="LoadingPanel" runat="server" Modal="True">
    </dx:ASPxLoadingPanel>

    <%--<dx:ASPxCallback ID="callBackUpdateTireSetTargetGroup" ClientInstanceName="callBackUpdateTireSetTargetGroup" runat="server" OnCallback="callBackUpdateTireSetTargetGroup_Callback">
        <ClientSideEvents CallbackError="CallbackError" CallbackComplete="OnCallbackUpdateTireSetTargetGroupComplete" />
    </dx:ASPxCallback>--%>

    <h4>Målgruppe</h4>
    <table>
        <tr>
            <td>
                Dæktype
            </td>
            <td>
                Mønster
            </td>
            <td>
                Kunde filter
            </td>
            <td>
                
            </td>
        </tr>
        <tr>
            <td valign="top">
                <dx:ASPxComboBox ID="ddlTireType" ClientInstanceName="ddlTireType" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="True" Value="2" Text="Sommerdæk" />
                        <dx:ListEditItem Value="3" Text="Vinterdæk" />
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td valign="top">
                <table width="150px">
                    <tr>
                        <td>VF</td>
                        <td>HF</td>
                        <td>VB</td>
                        <td>HB</td>
                    </tr>
                    <tr>
                        <td>
                            <dx:ASPxTextBox ID="txtVF" ClientInstanceName="txtVF" runat="server" Width="37px" Text="4">
                            </dx:ASPxTextBox>
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtHF" ClientInstanceName="txtHF" runat="server" Width="37px" Text="4">
                            </dx:ASPxTextBox>
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtVB" ClientInstanceName="txtVB" runat="server" Width="37px" Text="4">
                            </dx:ASPxTextBox>
                        </td>
                        <td>
                            <dx:ASPxTextBox ID="txtHB" ClientInstanceName="txtHB" runat="server" Width="37px" Text="4">
                            </dx:ASPxTextBox>
                        </td>
                    </tr>
                </table>
            </td>
            <td valign="top">
                <dx:ASPxRadioButtonList ID="rblCustomerFilter" AutoPostBack="false" ClientInstanceName="rblCustomerFilter" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="true" Value="0" Text="Privat kunder" />
                        <dx:ListEditItem Value="1" Text="Erhvervs kunder" />
                    </Items>
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { CustomerFilterSelected();}" />
                </dx:ASPxRadioButtonList>
                <dx:ASPxComboBox ID="ddlBusinessCustomer" ClientInstanceName="ddlBusinessCustomer" runat="server" Width="150px" ClientEnabled="false">
                </dx:ASPxComboBox>
            </td>
            <td>
                <dx:ASPxButton ID="btnUpdateTireSetTargetGroup" ClientInstanceName="btnUpdateTireSetTargetGroup" runat="server" Text="Opdater målgruppe" Width="100px">
                    <ClientSideEvents Click="function(s, e) { UpdateTireSetTargetGroup();}" />
                </dx:ASPxButton>
                <dx:ASPxButton ID="btnExport" ClientInstanceName="btnExport" runat="server" Width="100px" Text="Export" onclick="btnExport_Click">
                </dx:ASPxButton>
            </td>
        </tr>
    </table>
    <hr />

    <dx:ASPxGridView ID="gvTireSetTargetGroup" ClientInstanceName="gvTireSetTargetGroup" runat="server" 
        KeyFieldName="TireSetId" AutoGenerateColumns="false" EnableCallBacks="True" OnCustomCallback="gvTireSetTargetGroup_CustomCallback"
        OnCustomUnboundColumnData="gvTireSetTargetGroup_CustomUnboundColumnData">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="true" ShowFilterRow="True" ShowFooter="True"  />
        <SettingsPager AlwaysShowPager="True" PageSize="50" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} emner)" 
                Text="Side {0} af {1} ({2} emner)" />
        </SettingsPager>
        <SettingsText ConfirmDelete="" GroupPanel="Træk kolonne hertil for at gruppere efter den" HeaderFilterShowAll="Vis alle" />
        <SettingsBehavior ConfirmDelete="false" AllowGroup="true" AllowDragDrop="false" AllowFocusedRow="true" />
        <Columns>
            <dx:GridViewDataColumn FieldName="TireSetId" VisibleIndex="1" Caption="Hjulsæt Id">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Width" VisibleIndex="1" Caption="Bredde">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Height" VisibleIndex="1" Caption="Højde">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Size" VisibleIndex="1" Caption="Diameter">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TireLoadIndexDescription" VisibleIndex="1" Caption="Loadindex">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="TireSpeedIndexDescription" VisibleIndex="1" Caption="Hastighed">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Name" VisibleIndex="1" Caption="Navn">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="CustomerId" VisibleIndex="2" Caption="Kundenr">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="RegistrationNumber" VisibleIndex="2" Caption="Regnr">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="LeftFrontTirePattern" VisibleIndex="3" Caption="VF">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="RightFrontTirePattern" VisibleIndex="3" Caption="HF">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="LeftRearTirePattern" VisibleIndex="3" Caption="VB">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="RightRearTirePattern" VisibleIndex="3" Caption="HB">
            </dx:GridViewDataColumn>
            <dx:GridViewDataTextColumn FieldName="ReplaceQuantity" VisibleIndex="3" UnboundType="Integer" Caption="Antal dæk">
            </dx:GridViewDataTextColumn>
            <dx:GridViewDataColumn VisibleIndex="3">
                <DataItemTemplate>
                    <dx:ASPxButton ID="btnCreateSingleQuotation" runat="server" ClientInstanceName="btnCreateSingleQuotation" Text="Enkelt tilbud" ToolTip="Klik for at oprette enkelt tilbud til pågældende kunde" AutoPostBack="false"
                        ClientSideEvents-Click='<%# "function(s, e) { CreateSingleQuotation(" + Container.KeyValue + "); }" %>'>
                    </dx:ASPxButton>                                           
                </DataItemTemplate>
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn VisibleIndex="4">
                <DataItemTemplate>
                    <dx:ASPxButton ID="btnCreateGroupQuotation" runat="server" ClientInstanceName="btnCreateGroupQuotation" Text="Gruppe tilbud" ToolTip="Klik for at oprette tilbud til alle kunder indenfor denne gruppering" AutoPostBack="false"
                        ClientSideEvents-Click='<%# "function(s, e) { CreateGroupQuotation(" + Container.KeyValue + "); }" %>'>
                    </dx:ASPxButton>                                           
                </DataItemTemplate>
            </dx:GridViewDataColumn>
        </Columns>
        <TotalSummary>
            <dx:ASPxSummaryItem FieldName="ReplaceQuantity" SummaryType="Sum" />
        </TotalSummary>
        <GroupSummary>
            <dx:ASPxSummaryItem FieldName="Name" ShowInColumn="Name" SummaryType="Count" />
            <dx:ASPxSummaryItem FieldName="ReplaceQuantity" ShowInColumn="ReplaceQuantity" SummaryType="Sum" />
        </GroupSummary>    
    </dx:ASPxGridView>

    <dx:ASPxGridViewExporter ID="gvExport" runat="server" GridViewID="gvTireSetTargetGroup">
    </dx:ASPxGridViewExporter>

</asp:Content>
